import {createRouter, createWebHashHistory} from 'vue-router';

/**
 * 创建一个可以被 Vue 应用程序使用的路由实例
 * @method createRouter(options: RouterOptions): Router
 * @link 参考：https://next.router.vuejs.org/zh/api/#createrouter
 */
export const router = createRouter({
    history: createWebHashHistory(),
    //静态路由
    routes: [
        {
            path: '/',
            name: '/',
            redirect: '/test/index'
        },
        {
            path: '/index',
            name: '/index',
            component: () => import('/@/views/index.vue'),
            meta: {
                title: '首页',
            },
        },
        {
            path: '/test/index',
            name: '/test/index',
            component: () => import('/@/views/test/index.vue'),
            meta: {
                title: '测试',
            },
        }
    ]
});

// 路由加载前
router.beforeEach(async (to, from, next) => {
    console.log('router start');
    next();
    console.log('router end')
});

// 路由加载后
router.afterEach(() => {
    console.log('router over')
});

// 导出路由
export default router;
